package top.yxqz.req;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author Mr.余
 * @date 2022/11/21
 * @package top.yxqz.req
 * 路径相关的方法
 */
@WebServlet("/demo2")
public class ReqDemo2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //本机地址：服务器地址
        String localAddr = request.getLocalAddr();
        //本机名称：服务器名称
        String localName = request.getLocalName();
        //本机端口：服务器端口
        int localPort = request.getLocalPort();
        //来访者ip
        String remoteAddr = request.getRemoteAddr();
        //来访者主机
        String remoteHost = request.getRemoteHost();
        //来访者端口
        int remotePort = request.getRemotePort();
        //统一资源标识符
        String URI = request.getRequestURI();
        //统一资源定位符
        String URL = request.getRequestURL().toString();
        //获取查询字符串
        String queryString = request.getQueryString();
        //获取Servlet映射路径
        String servletPath = request.getServletPath();

        //输出内容
        PrintWriter writer = response.getWriter();
        writer.println("getLocalAddr() is :" + localAddr);
        writer.println("getLocalName() is :" + localName);
        writer.println("getLocalPort() is :" + localPort);
        writer.println("getRemoteAddr() is :" + remoteAddr);
        writer.println("getRemoteHost() is :" + remoteHost);
        writer.println("getRemotePort() is :" + remotePort);
        writer.println("getRequestURI() is :" + URI);
        writer.println("getRequestURL() is :" + URL);
        writer.println("getQueryString() is :" + queryString);
        writer.println("getServletPath() is :" + servletPath);
    }
}
